package com.example.demo.service;

import com.example.demo.entity.TableEquipment;
import com.example.demo.entity.TableEquipment;
import com.example.demo.mapper.TableEquipmentMapper;
import com.example.demo.mapper.TableEquipmentMapper;
import com.example.demo.utils.PageDataList;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EquipementService {




        @Autowired
        private TableEquipmentMapper tableEquipmentMapper;
        

        public PageDataList<TableEquipment> getList(TableEquipment usersDto){
            List<TableEquipment> resultList = new ArrayList<>();
            PageHelper.startPage(usersDto.getPageNumber(), usersDto.getPageSize());
            List<TableEquipment> dbResult = tableEquipmentMapper.getList(usersDto);

            Page<TableEquipment> dbResultPage = (Page<TableEquipment>) dbResult;
            for (TableEquipment dbItem : dbResultPage.getResult()) {
                resultList.add(dbItem);
            }

            PageDataList<TableEquipment> pageDataList = new PageDataList<>(dbResultPage.getTotal(),
                    dbResultPage.getPages(),
                    dbResultPage.getPageNum(), dbResultPage.getPageSize());
            pageDataList.setList(resultList);
            return pageDataList;

        }




    

}
